package cn.wbu.zyh.controller.user;

import cn.wbu.zyh.dto.ArticleDTO;
import cn.wbu.zyh.dto.TagDTO;
import cn.wbu.zyh.dto.TagPageQueryDTO;
import cn.wbu.zyh.entity.Article;
import cn.wbu.zyh.result.PageResult;
import cn.wbu.zyh.result.Result;
import cn.wbu.zyh.service.TagService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/category")
@Slf4j
public class TagController {
    @Autowired
    private TagService tagService;
    @GetMapping("/list")
    @ApiOperation("笔记分页")
    public Result<PageResult> page(TagPageQueryDTO tagPageQueryDTO){
        log.info("笔记分页查询,参数为：:{}",tagPageQueryDTO);
        PageResult pageResult = tagService.pageQuery(tagPageQueryDTO);
        return Result.success(pageResult);
    }

    @PostMapping("/add")
    @ApiOperation("新增tag")
    public Result save(@RequestBody TagDTO tagDTO) {
        tagService.save(tagDTO);
        return Result.success();
    }

    @PutMapping
    @ApiOperation("修改笔记")
    public Result update(@RequestBody TagDTO tagDTO) {
        tagService.update(tagDTO);
        return Result.success();
    }

    @DeleteMapping
    @ApiOperation("删除笔记")
    public Result delete(@RequestParam Long id){
        tagService.deleteTag(id);
        return Result.success();
    }
}
